# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm/configs/apq8084_sec_defconfig
#                         arch/arm/configs/apq8084_sec_kccat6_eur_defconfig
#                         arch/arm/configs/selinux_defconfig

pkgname=linux-samsung-kccat6
pkgver=3.10.100
pkgrel=0
pkgdesc="Samsung Galaxy S5 Plus kernel fork"
arch="armv7"
_carch="arm"
_flavor="samsung-kccat6"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="bash bc bison devicepkg-dev flex openssl-dev perl gcc6 xz dtbtool"

# Source
_repository="android_kernel_samsung_apq8084"
_commit="45470c5e5fde343926188c3e78a3c652c81408cb"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/LineageOS/$_repository/archive/$_commit.tar.gz
	$_config
	gcc8-fix-put-user.patch
	gcc10-extern_YYLOC_global_declaration.patch
"
builddir="$srcdir/$_repository-$_commit"
_outdir="out"

# Compiler: GCC 6 (doesn't boot when compiled with newer versions)
if [ "${CC:0:5}" != "gcc6-" ]; then
	CC="gcc6-$CC"
	HOSTCC="gcc6-gcc"
	CROSS_COMPILE="gcc6-$CROSS_COMPILE"
fi

prepare() {
	default_prepare
	. downstreamkernel_prepare
}

build() {
	unset LDFLAGS
	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
	dtbTool -s 2048 -p "scripts/dtc/" -o "arch/arm/boot/dt.img" "out/arch/arm/boot/dts/"
}

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor" "$_outdir"
	install -Dm644 "$builddir/arch/arm/boot/dt.img" \
		"$pkgdir/boot/dt.img"
}

sha512sums="a09b9f7ac2c70935678e2faac76d5db2d8d98e2dde17de3ed449f5e521c460f6c1d62056b670aba2c99ce0f6941991f8402f31a0696c5763fc799514d6bf3367  linux-samsung-kccat6-45470c5e5fde343926188c3e78a3c652c81408cb.tar.gz
63417753bc7d25d20fb41fcee4b9c5d12580d9da72441b6bf2b2556b40284b94f8b7900133edea6d96ab9b9b545480132ff985fd3d84f8d40bd108de254dd241  config-samsung-kccat6.armv7
197d40a214ada87fcb2dfc0ae4911704b9a93354b75179cd6b4aadbb627a37ec262cf516921c84a8b1806809b70a7b440cdc8310a4a55fca5d2c0baa988e3967  gcc8-fix-put-user.patch
2b48f1bf0e3f70703d2cdafc47d5e615cc7c56c70bec56b2e3297d3fa4a7a1321d649a8679614553dde8fe52ff1051dae38d5990e3744c9ca986d92187dcdbeb  gcc10-extern_YYLOC_global_declaration.patch"
